package nu.aing.P20140811;

import java.util.Arrays;

/**
 * @author memekmaut@gmail.com
 */
public class ManySquares {
    
    public static void main(String[] args) {
        ManySquares obj = new ManySquares();
        System.out.println(
                obj.howManySquares(new int[] {1,1,2,2,1,1,2}
        ));
        System.out.println(
                obj.howManySquares(new int[] {3, 1, 4, 4, 4, 10, 10, 10, 10}
        ));
        System.out.println(
                obj.howManySquares(new int[] {1,2,3,4,1,2,3,4,1,2,3,1,2,3,4,1,2,3,3,3}
        ));
        System.out.println(
                obj.howManySquares(new int[] {1,1,1,2,1,1,1,3,1,1,1}
        ));
        System.out.println(
                obj.howManySquares(new int[] {2,2,4,4,8,8}
        ));
    }
    
    public int howManySquares(int[] sticks) {
        Arrays.sort(sticks);
        int c = 0, t = 0;
        for(int i = 1; i < sticks.length; i++) {
            t = sticks[i] == sticks[i-1] ? (t == 0 ? t = 2 : (t == 4 ? 0 : ++t)) : 0;
            c = t == 4 ? ++c : c;
        }
        return c;
    }
}
